package com.scaffold.card.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import wangjg.commons.page.Page;

import com.scaffold.authority.dao.BasicBizDAO;
import com.scaffold.card.entity.Category;

@Repository
public class CategoryDAO extends BasicBizDAO<Category,Long>{

	public List<Category> pageQuery(Page page, String keyword) {
		DetachedCriteria criteria = DetachedCriteria.forClass(this.persistentClass);
		if (keyword != null && !keyword.isEmpty()) {
			criteria.add(Restrictions.like("name", keyword, MatchMode.ANYWHERE).ignoreCase());
		}
		criteria.addOrder(Order.asc("sortNo"));
		return this.findByCriteria(criteria, page);
	}

	public List<Category> pageQuery(Page page, String keyword, String enabled) {
		DetachedCriteria criteria = DetachedCriteria.forClass(this.persistentClass);
		if (keyword != null && !keyword.isEmpty()) {
			criteria.add(Restrictions.like("name", keyword, MatchMode.ANYWHERE).ignoreCase());
		}
		if(enabled!=null){
			criteria.add(Restrictions.eq("enabled", enabled));
		}
		criteria.addOrder(Order.asc("sortNo"));
		return this.findByCriteria(criteria, page);
	}
	
	public List<Category> findAll() {
		return this.pageQuery(null, null);
	}

	public List<Category> queryValidList(Page page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(this.persistentClass);
		criteria.add(Restrictions.eq("enabled", "Y"));
		criteria.addOrder(Order.asc("sortNo"));
		return this.findByCriteria(criteria, page);
	}

}
